import functools
import logging
from typing import Callable

def trace_citations(func: Callable) -> Callable:
    """引用追踪装饰器"""
    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        logger = logging.getLogger(__name__)
        try:
            result = func(self, *args, **kwargs)
            if hasattr(self, 'citations'):
                logger.debug(f"Citation Status after {func.__name__}:")
                logger.debug(f"Total citations: {len(self.citations)}")
                if self.citations:
                    logger.debug(f"Last citation: {self.citations[-1]}")
            return result
        except Exception as e:
            logger.error(f"Error in {func.__name__}: {str(e)}")
            raise
    return wrapper
